package com.chuanye.jiguangimdemo.activitys;

import androidx.fragment.app.Fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.chuanye.jiguangimdemo.R;

import com.chuanye.jiguangimdemo.adapters.ViewPagerAdapter;
import com.chuanye.jiguangimdemo.fragments.FriendFragment;
import com.chuanye.jiguangimdemo.fragments.GroupFragment;
import com.chuanye.jiguangimdemo.views.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * 确认消息页面  验证消息
 */
public class VerificationMessageActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "VerificationMessageActivity";
    private Context mContext;
    private ImageView verifimess_back_iv;
    private RadioGroup verifimess_verification_rg;
    private RadioButton verifimess_friend_rb;
    private RadioButton verifimess_group_rb;
    private NoScrollViewPager verifimess_viewpager;


    private List<Fragment> mFragmentList;

    private int mCurTabIndex;//选中


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verification_message);
        mContext = this;

        //初始化布局view
        initView();
    }

    /**
     * 初始化布局view
     */
    private void initView() {
        //返回
        verifimess_back_iv = findViewById(R.id.verifimess_back_iv);
        verifimess_back_iv.setOnClickListener(this);
        //RadioGroup
        verifimess_verification_rg = findViewById(R.id.verifimess_verification_rg);
        //RadioButton
        verifimess_friend_rb = findViewById(R.id.verifimess_friend_rb);
        verifimess_group_rb = findViewById(R.id.verifimess_group_rb);

        //viewpager
        verifimess_viewpager = findViewById(R.id.verifimess_viewpager);


        //添加Fragment
        mFragmentList = new ArrayList<>();
        mFragmentList.add(new FriendFragment());//好友验证
        mFragmentList.add(new GroupFragment());//群组验证

        //设置默认选中
        verifimess_verification_rg.check(R.id.verifimess_friend_rb);
        //设置适配器
        verifimess_viewpager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), mFragmentList));

        //设置选中事件监听
        verifimess_verification_rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.verifimess_friend_rb://好友验证
                        mCurTabIndex = 0;
                        break;
                    case R.id.verifimess_group_rb://群组验证
                        mCurTabIndex = 1;
                        break;
                }
                //设置当前条目
                verifimess_viewpager.setCurrentItem(mCurTabIndex, false);
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.verifimess_back_iv://返回
                finish();
                break;
        }
    }
}
